﻿Namespace Catalog.Search
    ''' <summary>
    ''' The genres catalog is used to retrieve a listing of all of the top-level genres on Beatport.
    ''' </summary>
    Public Class GenresQuery
        Inherits Query
        ''' <summary>
        ''' Which genre id specifically to retrieve (limits to a single genre).
        ''' </summary>
        Public Property Id As Integer
        ''' <summary>
        ''' Which genre specifically to retrieve (limits to a single genre).
        ''' A slug is a human-readable string representing this genre with all special characters removed.
        ''' </summary>
        Public Property Slug As String
        ''' <summary>
        ''' Determines whether or not to retrieve subgenres along with the parent genres.
        ''' </summary>
        Public Property SubGenres As Boolean

        Public Sub New()
            MyBase.New()
        End Sub

        Public Sub New(id As Integer, subgenres As Boolean)
            Me.New()
            Me.Id = id
            Me.SubGenres = subgenres
        End Sub

        Public Sub New(slug As String, subgenres As Boolean)
            Me.New()
            Me.Slug = slug
            Me.SubGenres = subgenres
        End Sub

        Public Overrides Function GetUrl() As System.Uri
            Dim url As String = Beatport.CATALOG_GENRES_URL
            Dim queryStr As New List(Of String)

            If Me.Id <> Nothing Then
                queryStr.Add(String.Format("id={0}", Me.Id))
            ElseIf Me.Slug.Trim.Length > 0 Then
                queryStr.Add(String.Format("slug={1}", Me.Slug))
            End If

            If Me.SubGenres Then
                queryStr.Add("subgenres=true")
            End If

            If queryStr.Count > 0 Then
                url = String.Format("{0}?{1}", url, String.Join("&", queryStr.ToArray))
            End If

            Return New Uri(url)
        End Function
    End Class
End Namespace